<template>
  <div class="potentialCustomers">
    <page-header :title="'报名信息查看'"></page-header>
    <div class="search_area">
      <el-row>
        <el-form :form="queryForm" label-width="1rem">
          <el-col :span="6">
            <el-form-item label="审批状态">
              <el-select v-model="queryForm.auditStatus" clearable placeholder="请选择" style="width:100%">
                  <el-option v-for="item in status" :label="item.described" :value="item.code" :key="item.code"></el-option>
                </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="岗位名称">
              <el-input type="text" v-model="queryForm.postName" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="指导教师">
              <el-select v-model="queryForm.teacherId" placeholder="请选择指导教师" style="width:100%" clearable>
                <el-option v-for="item in teacherList" :label="item.userName" :key="item.uuid" :value="item.uuid"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
        <el-col :span="6">
          <div class="btn_area">
            <el-button class="confrim" @click="queryList">查询</el-button>
            <el-button class="cancle" @click="reset">重置</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
    <table-list :fields="fields" :list="list" :pagination="pagination" :total="total" @sizeChange="handleSizeChange" @currentChange="handleCurrentChange" :panduan="true"  @handle="onHandle"></table-list>
  </div>
</template>
<script>
import tableList from '@/components/table.vue'
import pageHeader from '@/components/pageHeader.vue'
export default {
  name: 'potentialCustomers',
  components: {
    tableList,
    pageHeader
  },
  data() {
    return {
      queryForm: {
        "auditStatus": "",
        "postName": "",
        "teacherId": ""
      },
      list: [],
      fields: [
        {
          prop: 'rowNum',
          label: '序号',
          align: 'center'
        },
        {
          prop: 'postName',
          label: '岗位名称',
          align: 'center'
        },
        {
          prop: 'projectHeading',
          label: '实习计划',
          align: 'center'
        },
        {
          prop: 'internshipWayName',
          label: '实习方式',
          align: 'center'
        },
        {
          prop: 'teacherName',
          label: '指导教师',
          align: 'center'
        },
        {
          prop: 'auditStatusName',
          label: '审核状态',
          align: 'center'
        },
        {
          prop: 'oper',
          label: '操作',
          align: 'center',
          btns: [
            {type: 'info',desc:'取消申请'}
          ]
        }
      ],
      pagination: {
        currentPage: 1,
        pageSize: 10
      },
      total: 0,
      status: [],
      teacherList: []
    }
  },
  methods: {
    onHandle(data) {
      let {row,type} = data;
      console.log(data)
      let auditStatus = '04'
      let obj = {
        auditStatus,
        postId: row.postId,
        adminId: JSON.parse(sessionStorage.getItem('user')).uuid,
        auditId: row.auditId,
      }
      console.log(obj);
      this.$post(this.$api.audit.update,this.reqData(obj)).then(res => {
        if (res.data.code == 200) {
          this.$message.success(res.data.message);
          this.queryList();
        } else {
          this.$message.error(res.data.message);
        }
      })
    },
    btnClick() {
      this.queryList();
    },
    reset() {
      this.queryForm = {
        "auditStatus": "",
        "postName": "",
        "teacherId": ""
      }
    },
    queryList() {
      this.queryForm.adminId = JSON.parse(sessionStorage.getItem('user')).uuid
      this.$post(this.$api.audit.student,this.reqData(this.queryForm,this.pagination.currentPage,this.pagination.pageSize)).then(res => {
        if (res.data.code === 200) {
          console.log(res.data.data.list);
          this.list = res.data.data.list;
          this.list.forEach((item,index) => {
            item.rowNum = (this.pagination.currentPage - 1) * this.pagination.pageSize + index + 1
          })
          this.total = this.list.length;
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    querystatus() {
      this.$post(this.$api.common.code,this.reqData('audit_status')).then(res => {
        if (res.data.code === 200) {
          this.status = res.data.data;
        }
      })
    },
    handleSizeChange(val) {
      console.log(val);
      this.pagination.pageSize = val;
      this.queryList();
    },
    handleCurrentChange(val) {
      console.log(val);
      this.pagination.currentPage = val;
      this.queryList();
    },
    queryTeacherList() {
      let url = this.$api.user.list;
      this.$post(url,this.reqData({},this.pagination.currentPage,this.pagination.pageSize)).then(res => {
        if (res.data.code == 200) {
          this.teacherList = res.data.data.filter(item => item.permission == '1');
          console.log(this.teacherList);
        } else {
          this.$message.error(res.data.message)
        }
      })
    }
  },
  mounted() {
    this.queryTeacherList();
    this.querystatus();
    this.queryList();
  }
}
</script>
<style scoped>
.potentialCustomers {
  background: #fff;
  overflow: hidden;
  padding-bottom: 0.15rem;
}
</style>